<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <title>找回密码</title>
    <link rel="stylesheet" href="css/base.css" />
    <link rel="stylesheet" href="css/all.css" />
    <link rel="stylesheet" href="css/retrieve-password.css" />
</head>
<body>
<div>
    <div class="heads">
        <span onclick="go()"><img src="img/zuojiantou.png" alt="" class="arrows"></span>
        <h1 class="titles">找回密码</h1>
    </div>
    <div class="middle">
        <form action="">
            <div class="verify">
                <div class="resetUpwd">
                    <input type="text" placeholder="请输入手机号码" class="resetUpwd-input" id="retrieve-userName"/>
                </div>
                <div class="resetUpwd">
                    <input type="text" placeholder="请输入验证码" class="resetUpwd-input" id="retrieve-code"/>
                    <button class="acquire-code" type="button">
                        验证码
                    </button>
                </div>
                <div class="resetUpwd">
                    <input type="password" placeholder="请输入新密码" class="resetUpwd-input" id="retrieve-password"/>
                </div>
                <div class="resetUpwd">
                    <input type="password" placeholder="请再次确认新密码" class="resetUpwd-input" id="retrieve-confirmPassword"/>
                </div>
                <div type="button" class="c-4e" >
                    <div class="logon">确定</div>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="js/jquery.js"></script>
<script src="js/x_rem.js"></script>
<script src="js/secondLevel.js"></script>
<script src="js/all.js"></script>
<script>
	(()=>{
		var userName = $("#retrieve-userName");   //账号
		var Password = $("#retrieve-password");    //新密码
		var confirmPassword = $("#retrieve-confirmPassword");      //确定新密码
		var code = $("#retrieve-code")       //验证码
		 
		//获取验证码
		$(".acquire-code").click(function(){
			var that = $(this);  //保存this
			
			if(!vali(userName, /^1[0-9]{10}$/, "请输入正确的手机号")){

			}else{
				$.ajax({
					type:"post",
					url: Url+ "/user/doCode",
					xhrFields: {
						withCredentials: true
					},
					data:{
						"mobilePhone":  userName.val()
					},
					success:function(data){
						console.log(data);
						if(data.success){
							count(that);    //让获取验证码变成倒计时
							popup("验证码发送成功");   //弹窗提示
						}else{
							popup("获取失败,请检查网络");
						} 
					},
					error:function(err){
						console.log(err);
					}
				})
			}
					
		})
		
		
			//忘记密码
		$(".logon").click(()=>{
				if(!vali(userName , /^1[0-9]{10}$/, "请输入正确的手机号")){
					
				}else if(code.val() == ""){   //如果验证码为空的话
					popup("验证码不能为空");  //就提示
				}else if(!vali(Password, /^[a-zA-Z0-9_]{6}$/ , "请输入正确的密码格式")){
					
				}else if(Password.val() != confirmPassword.val()){    //如果确认密码不等于登录密码
					popup("两次密码不一致");  //就提示
				}else{
					console.log(userName.val());
					console.log(Password.val());
					console.log(code.val());
					$.ajax({
						type:"post",
						url: Url + "/user/updatePassword2",
						xhrFields:{
							withCredentials:true
						},
						data:{
							"userName": userName.val(),
							"password": Password.val(),
							"newCode":code.val()
						},
						success:function(data){
							if(data.success){  //如果返回成功
								popup(data.message);
								//跳转到登录页面
								location.href = "login.html";
							}else{   //否则
								popup(data.message);
							}
							console.log(data);
						},
						error:function(err){
							console.log(err)
						}
					});
				}
		})
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	 
	})()
	
	
	
</script>

</body>
</html>